﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class LogBO : BaseBO
    {
        public const string FIELD_ID = "ID";
        public const string FIELD_ACCOUNT = "ACCOUNT";
        public const string FIELD_SOFTWARE = "SOFTWARE";
        public const string FIELD_FUNCTION = "FUNCTION";
        public const string FIELD_ACTION = "ACTION";
        public const string FIELD_DATA = "DATA";
        public const string FIELD_ACTION_TIME = "ACTION_TIME";
        public const string FIELD_RECORD_COUNT = "RECORD_COUNT";
        public const string FIELD_APP_NAME = "APP_NAME";

        private LogDAO objDAO;
        public LogBO()
        {
            objDAO = new LogDAO(Common.ConnectionUtil.DHQG_ADMIN_CONNECTION_STRING, DEFAULT_MAPPER_TYPE);
        }

        public LogBO(string connectionString)
        {
            objDAO = new LogDAO(connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<Log> GetDynamicListPaging(Log model, int pageIndex, int pageSize)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();

                return objDAO.GetDynamicListPaging(model, pageIndex, pageSize, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public Log GetById(long id)
        {
            try
            {
                Dictionary<string, string> mapDictionary = GetMapDictionary();
                
                return objDAO.GetById(id, mapDictionary);
            }
            catch
            {
                throw;
            }
        }

        public bool Save(Log model)
        {
            try
            {
                return objDAO.Save(model);
            }
            catch
            {                
                throw;
            }
        }

        public bool Delete(string[] listId)
        {
            try
            {
                return objDAO.Delete(listId);
            }
            catch
            {
                throw;
            }
        }

        private Dictionary<string, string> GetMapDictionary()
        {
            Dictionary<string, string> mapDictionary = new Dictionary<string, string>();
            mapDictionary.Add(Log.FIELD_ID, LogBO.FIELD_ID);
            mapDictionary.Add(Log.FIELD_ACCOUNT, LogBO.FIELD_ACCOUNT);
            mapDictionary.Add(Log.FIELD_SOFTWARE, LogBO.FIELD_SOFTWARE);
            mapDictionary.Add(Log.FIELD_FUNCTION, LogBO.FIELD_FUNCTION);
            mapDictionary.Add(Log.FIELD_DATA, LogBO.FIELD_DATA);
            mapDictionary.Add(Log.FIELD_ACTION, LogBO.FIELD_ACTION);
            mapDictionary.Add(Log.FIELD_ACTION_TIME, LogBO.FIELD_ACTION_TIME);
            mapDictionary.Add(Log.FIELD_RECORD_COUNT, LogBO.FIELD_RECORD_COUNT);
            mapDictionary.Add(Log.FIELD_APP_NAME, LogBO.FIELD_APP_NAME);
            return mapDictionary;
        }
    }
}
